package org.argetr.resim;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import org.argetr.resim.ui.viewers.ImageView;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.forms.editor.*;

public class ResimProjectEditor extends FormEditor {

	private List<ShapesEditor> _shapesEditorList;
	public static final String EDITOR_ID = "org.argetr.resim.editors.resimprojecteditor";
	
	public ResimProjectEditor()
	{
		super();
		_shapesEditorList = new ArrayList<ShapesEditor>();
	}
	
	@Override
	protected void addPages() {
		// TODO Auto-generated method stub
		try {
			//addPage(new ShapeEditorPage(this,EDITOR_ID,"Editor"));
			ShapesEditor shapesEditor = new ShapesEditor();
			shapesEditor.setInput(getEditorInput());
			int pageIndex = addPage(shapesEditor,shapesEditor.getEditorInput());
			setPageText(pageIndex,"Editor");
			_shapesEditorList.add(shapesEditor);
		} catch (PartInitException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	/*
	    * @see org.eclipse.ui.part.EditorPart#doSaveAs()
	    */
	   @Override
	   public void doSaveAs() {/* Not allowed */}

	   /*
	    * @see org.eclipse.ui.part.EditorPart#getEditorInput()
	    */
	   @Override
	   public ShapesEditorInput getEditorInput() {
	      return (ShapesEditorInput) super.getEditorInput();
	   }

	   /*
	    * @see org.eclipse.ui.forms.editor.FormEditor#init(org.eclipse.ui.IEditorSite,
	    *      org.eclipse.ui.IEditorInput)
	    */
	   @Override
	   public void init(IEditorSite site, IEditorInput input) throws PartInitException {
	      if (!(input instanceof ShapesEditorInput)) {
	         throw new PartInitException("The input is not an instance of " + ShapesEditorInput.class);
	      }
	      super.init(site, input);
	      String partname = ShapesEditorInput.class.cast(input).getName();
	      File file = new File(partname);	      
	      setPartName(file.getName());
	   }

	   /*
	    * @see org.eclipse.ui.part.EditorPart#isSaveAsAllowed()
	    */
	   @Override
	   public boolean isSaveAsAllowed() {
	      return false;
	   }

	@Override
	public void doSave(IProgressMonitor monitor) {
		// TODO Auto-generated method stub
		((ShapesEditor)getActiveEditor()).doSave(monitor);
	}

}
